# Some Portions Copyright (c) 2006 IBM and others. All Rights Reserved.

srcdir = @srcdir@
top_srcdir = @top_srcdir@

top_builddir = ../..

subdir = tools/tzcode

include $(top_builddir)/icudefs.mk

OBJECTS= zic.o localtime.o asctime.o scheck.o ialloc.o
TZDATA = $(firstword $(wildcard ./tzdata*.tar.gz) $(wildcard $(srcdir)/tzdata*.tar.gz))

ifeq ($(TZDATA),)
all: 
	@echo ERROR tzdata*.tar.gz can\'t be found.
	@false
else
all: icu_data
endif

PRIMARY_YDATA=	africa antarctica asia australasia \
		europe northamerica southamerica
YDATA=		$(PRIMARY_YDATA) pacificnew etcetera factory backward
NDATA=		systemv
SDATA=		solar87 solar88 solar89
TDATA=		$(YDATA) $(NDATA) $(SDATA)
YEARISTYPE=     ./yearistype

ZIC = ./zic
TZDIR=zoneinfo

CFLAGS+=-D_POSIX_C_SOURCE
CPPFLAGS+= -DTZDIR=\"$(TZDIR)\"

# more data
XDATA=zone.tab yearistype.sh leapseconds iso3166.tab
ICUDATA=ZoneMetaData.java icu_zone.txt tz2icu zoneinfo.txt



zic:		$(OBJECTS) yearistype $(srcdir)/tz2icu.h
		$(CC) $(CFLAGS) $(LFLAGS) -I$(srcdir) $(OBJECTS) $(LDLIBS) -o $@

tz2icu:		$(srcdir)/tz2icu.cpp $(srcdir)/tz2icu.h
		$(CXX) -W -Wall -I$(srcdir) -pedantic $(srcdir)/tz2icu.cpp -o $@

yearistype.sh: $(TZDATA)
	gunzip -d < $(TZDATA) | tar xf -

yearistype:	yearistype.sh
		cp yearistype.sh yearistype
		chmod +x yearistype

tz.alias:		$(srcdir)/tz.alias
	cp $< .

posix_only:	zic $(TDATA)
		$(ZIC) -y $(YEARISTYPE) -d $(TZDIR) -L /dev/null $(TDATA)


icu_data:	tz2icu posix_only tz.alias
		./tz2icu $(TZDIR) zone.tab `echo $(TZDATA) | sed -e "s/.*\/tzdata//;s/\.tar\.gz$$//"`

clean:
		-rm -f core *.o *.out zdump zic yearistype date
		@echo ICU specific cleanup:
		-rm -f $(ICUDATA)
		-rm -rf $(TZDIR)
ifneq ($(srcdir),.)
		-$(RMV) tz.alias
endif
ifneq ($(TZDATA),)
		-rm -rf `gunzip -d < $(TZDATA) | tar tf - | grep -o '[^ ]*$$' | tr '\n' ' '`
endif

dataclean: clean
	-rm -f $(TDATA) $(XDATA)

distclean:	dataclean clean
	-rm -f Makefile

Makefile: $(srcdir)/Makefile.in  $(top_builddir)/config.status
	cd $(top_builddir) \
	&& CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status


